﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Actuals.CoreDomain.Business;
using Actuals.Business;
using Actuals.CoreDomain;

namespace Actuals
{
    public partial class AddTeam : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {
                if (Request.QueryString["Mode"] != null)
                {

                    string _mode = Request.QueryString["Mode"].ToString();
                    ViewState["Mode"] = _mode;
                    string _teamId = Request.QueryString["TeamId"].ToString();
                    hidTeamId.Value = _teamId;
                    PopulateTeam(Int32.Parse(_teamId));
                }
            }


        }

        protected void PopulateTeam(Int32 teamId)
        {
            IBusinessTeam businessTeam = new BusinessTeam();
            ITeam team = businessTeam.GetTeam(teamId);

            txtTeamDescription.Text = team.TeamDescription;

        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {

                ITeam team= new Team();

                team.TeamDescription= txtTeamDescription.Text;
             
                IBusinessTeam businessTeam= new BusinessTeam();
                if (ViewState["Mode"] != null)
                {
                    team.TeamId = int.Parse(hidTeamId.Value);
                    businessTeam.UpdateTeam(team);
                }
                else
                    businessTeam.AddTeam(team);

                lblMsg.Text = "Saved!";
            }
            catch (Exception ex)
            {
                lblMsg.Text = ex.Message;
            }

        }


    }
}